package com.mcms.web.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.mcms.service.UserService;
import com.mcms.web.LoginCommand;

/**
 * 客户回访处理类
 * @author 
 */
public class CallBackManager extends AbstractCommandController {
	private UserService userService;

	public CallBackManager() {
		setCommandClass(LoginCommand.class);
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	protected ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.println("Begin:CallBackManager ");
		
		HttpSession session = request.getSession(false);
		System.out.println("ModelAndView-----"+session.getId());
//		session.setAttribute("user", "servlet");
		System.out.println("-----------------"+session.getAttribute("user"));
		/**参数获取*/
		String actionType = request.getParameter("actionType");// 控制跳转参数
		String userName = request.getParameter("userName");
		String deptCode = request.getParameter("deptCode");
		
		System.out.println("at:"+actionType+";un:"+userName+";deptCode="+deptCode);
		
		/**登陆页跳转*/
		if( actionType!=null && actionType.trim().length()>0 ){
			if(actionType.equals("callBackList")){
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户回访
					return new ModelAndView("custom/qddepart/customCallBackAlertList");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/customCallBackAlertList");
				}else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/customCallBackAlertList");
				}
			}else if(actionType.equals("showContent")){// 高级检索条件页展示
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的高级检索
					return new ModelAndView("custom/qddepart/advancedQuery_qd");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/advancedQuery_xs");
				}else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/advancedQuery_kf");
				}
			}else if(actionType.equals("modifyCallBackPlan")){// 修改回访计划信息
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的修改回访计划
					return new ModelAndView("custom/qddepart/modifyCallBackPlan");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/modifyCallBackPlan");
				}else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/modifyCallBackPlan");
				}
			}else if(actionType.equals("showCallBackRecord")){// 回访记录展示
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的回访记录展示
					return new ModelAndView("custom/qddepart/viewCallBackRecord");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/viewCallBackRecord");
				}else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/viewCallBackRecord");
				}
			}else if(actionType.equals("showCallBackContent")){// 编辑用户基本信息及就诊信息
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的编辑用户基本信息及就诊信息
					return new ModelAndView("custom/qddepart/editCallBackInfo");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/editCallBackInfo");
				}else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/editCallBackInfo");
				}
			}else if(actionType.equals("viewCallBackContent")){// 查看用户基本信息及就诊信息
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的查看用户基本信息及就诊信息
					return new ModelAndView("custom/qddepart/viewCallBackInfo");
				}else if(deptCode.equals("xs")){
					return new ModelAndView("custom/xsdepart/viewCallBackInfo");
				}
				else if(deptCode.equals("kf")){
					return new ModelAndView("custom/kfdepart/viewCallBackInfo");
				}
			}
		}
		
		
		/**默认跳转至登陆页面*/
		return new ModelAndView("login");

	}
}
